#include <bits/stdc++.h>
using namespace std;
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
const int N=1e6+5;

void solve(){
    
    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n,m;
    cin>>n>>m;
    vector<int> va(n);
    vector<int> vb(m);
    vector<int> vc;
    vc.reserve(n+m);
    for(int i=0;i<n;i++)cin>>va[i];
    for(int i=0;i<m;i++)cin>>vb[i];
    vc.insert(vc.end(),va.begin(),va.end());
    vc.insert(vc.end(),vb.begin(),vb.end());
    sort(vc.begin(),vc.end());
    for(int i=1;i<vc.size();i++){
        bool ina1=0,ina2=0;
        for(int j=0;j<n;j++){
            if(vc[i]==va[j])ina1=1;
            if(vc[i-1]==va[j])ina2=1;
        }
        if(ina1&&ina2){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

    return 0;
}